package com.example.administrator.szb.fragments.fragment_forMy;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.example.administrator.szb.R;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.fragments.base.BaseFragment;
import com.example.administrator.szb.bean.WDGLBean;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;
import com.example.administrator.szb.http.HttpUtil;
import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.util.GetJsonDataUtil;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by D N on 2017/11/20.
 */

public class FragmentWGDLNEW extends BaseFragment {
    View view;
    @Bind(R.id.wdgl_fragment)
    RecyclerView wdglFragment;

    int type;
    int current_page = 1;
    int per_page = 10;
    public static ArrayList<WDGLBean.DataBean.PutForwardBean> mdata = new ArrayList<>();
    public static BaseAdapter<WDGLBean.DataBean.PutForwardBean> adapter;

    public static ArrayList<String> refer_id = new ArrayList<String>(){
        @Override
        public String toString() {
            String s= "";
            for (String info: refer_id) {
                s = s+ info+",";
            }
            return s;
        }
    };

    private WDGLBean mYcollectionbean;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        type = getArguments().getInt("type");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.wdgl_fragment, container, false);
        ButterKnife.bind(this, super.onCreateView(inflater, container, savedInstanceState));
        requestData();
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    private void requestData() {
        HashMap<String,String> map = new HashMap<>();
        map.put("code", HttpUtil.getParam());
        map.put("users_id", SampleApplicationLike.getUserloginInstance().getId()+"");
        map.put("genre",0+"");
        map.put("current_page",""+current_page);
        map.put("per_page",""+per_page);
        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        String url = URLAddress.URLBASE + URLAddress.URL_WDGL_New;
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, WDGLBean.class, url, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
